import { loginApi } from '@/api'

import { removeToken, getToken, setToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || '',
    userInfo: ''
  },
  // 存入token
  mutations: {
    setMyToken(state, token) {
      state.token = token
      setToken(token)
    },
    removeMyToken(state) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    // 登陆接口
    async participateLogin(store, loginFrom) {
      const res = await loginApi(loginFrom)
      store.commit('setMyToken', res.token)
      localStorage.setItem('info', JSON.stringify(res))
      return res
    }
  }
}
